package com.cx.base.day24_RabbitMQ;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;

/**
 * @Author: songyahui
 * @Date: 2020/8/30 18:49
 * @Version 1.0
 */
public class Send_Topic {
    private final static String EXCHANGE_NAME = "topic_exchange_test";
    private final static String QUEUE_NAME = "simple_queue22";

    public static void main(String[] args) {

        try {
//            获取到连接
            Connection con = ConnectionUtil.getConnection();
//            创建通道
            Channel channel = con.createChannel();
//            声明队列
            channel.exchangeDeclare(EXCHANGE_NAME, "topic", true);
//            消息内容
            String message = "更新商品：id = 1001";
//            发送消息，并且指定routing key 为：insert ，代替新增商品
            channel.basicPublish(EXCHANGE_NAME, "item.update", MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
            System.out.println("[商品服务：] sent '" + message + "'");
            channel.close();
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
